const connection = require('./db') // 获取连接实例

exports.message = function (req, res, next) {
    console.log(req.query);
    var insertsql = 'INSERT INTO comments(content,time) VALUES(?,?)'
    connection.query(insertsql, [req.query.content,req.query.time],(err, result, fields) => { 
        if (err) { 
            console.log('INSERT ERROR - ', err.message);
            throw err
        }
        console.log("INSERT SUCCESS");
    })
    connection.query('select * from comments', (err, comments) => {
        if (err) {
          res.send('query error')
        } else {
          // 将 MySQL 查询结果作为路由返回值
          res.send(comments)
        }
    })
}
